package com.ky.manage.activity;

import android.view.View;
import android.widget.RadioButton;
import android.widget.RadioGroup;

import com.ky.manage.R;
import com.ky.manage.adapter.FragmentTabAdapter;
import com.ky.manage.base.BaseActivity;
import com.ky.manage.fragment.OrderFragment;

import java.util.ArrayList;
import java.util.List;

import androidx.fragment.app.Fragment;
import androidx.viewpager.widget.ViewPager;

public class OrderListActivity extends BaseActivity {

    private List<Fragment> mFragmentList = new ArrayList<>();
    private OrderFragment allTabFragment, payTabFragment, commentTabFragment;

    private ViewPager mPager;
    private RadioGroup mTabRg;

    @Override
    protected int getLayoutId() {
        return R.layout.activity_order_list;
    }

    @Override
    protected void initView() {
        findView(R.id.back_iv).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });
        findTextView(R.id.page_title_tv, "我的订单");

        mTabRg = findView(R.id.tab_rg);
        mTabRg.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(RadioGroup group, int checkedId) {
                if (checkedId == R.id.all_tab_rb) {
                    mPager.setCurrentItem(0, true);
                } else if (checkedId == R.id.tab_no_pay_rb) {
                    mPager.setCurrentItem(1, true);
                } else if (checkedId == R.id.tab_no_comment_rb) {
                    mPager.setCurrentItem(2, true);
                }
            }
        });
        mPager = findView(R.id.view_pager);
        //全部
        allTabFragment = new OrderFragment(0);
        //状态（0所有， 1待支付， 2待评论）
        payTabFragment = new OrderFragment(1);
        commentTabFragment = new OrderFragment(2);
        mFragmentList.add(allTabFragment);
        mFragmentList.add(payTabFragment);
        mFragmentList.add(commentTabFragment);
        mPager.setAdapter(new FragmentTabAdapter(getSupportFragmentManager(), mFragmentList));
        mPager.setOffscreenPageLimit(2);
        mPager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {
            @Override
            public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {

            }

            @Override
            public void onPageSelected(int position) {
                RadioButton radioButton = (RadioButton) mTabRg.getChildAt(position);
                radioButton.setChecked(true);
            }

            @Override
            public void onPageScrollStateChanged(int state) {

            }
        });
    }

    @Override
    protected void initData() {

    }

    public static String getOrderStatus(int status) {
        String s = "";
        switch (status) {
            //0待发货, 1已签收， 2未付款，3已取消, 4已支付
            case 0:
                s = "待发货";
                break;
            case 1:
                s = "已签收";
                break;
            case 2:
                s = "未付款";
                break;
            case 3:
                s = "已取消";
                break;
            case 4:
                s = "已支付";
                break;
            default:
                break;
        }
        return s;
    }
}
